package main

import (
	"os"

	"go.uber.org/zap"
	"go.uber.org/zap/zapcore"
)

func initZapLogger(logpath string, loglevel zapcore.Level) *zap.Logger {
	file, err := os.Create(logpath)
	if err != nil {
		panic(err)
	}

	w := zapcore.AddSync(file)
	encoderConfig := zap.NewProductionEncoderConfig()
	encoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
	core := zapcore.NewCore(
		zapcore.NewConsoleEncoder(encoderConfig),
		w,
		loglevel,
	)
	logger := zap.New(core)
	return logger
}
